#!/bin/sh

DATE=`date +%Y%m%d%H%M%S`

. env.sh

PID=`ps -ef | grep java | grep "=$SERVER_NAME" | awk '{print $2}'`
echo $PID

if [ e$PID != "e" ]
then
    echo "JBoss SERVER - $SERVER_NAME is already RUNNING..."
    exit;
fi

#UNAME=`id -u -n`
#if [ e$UNAME != "ejboss" ]
#then
#    echo "Use jboss account to start JBoss SERVER - $SERVER_NAME..."
#    exit;
#fi  

export JAVA_OPTS="-Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.lang.ClassLoader.allowArraySyntax=true"


export JAVA_OPTS="-server -Xms1024m -Xmx1024m -XX:MaxPermSize=256m $JAVA_OPTS"
export JAVA_OPTS=" $JAVA_OPTS -verbose:gc "
export JAVA_OPTS=" $JAVA_OPTS -Djboss.messaging.datachanneludpport=$JBM_DC_PORT "
export JAVA_OPTS=" $JAVA_OPTS -Djboss.messaging.controlchanneludpport=$JBM_CC_PORT "

mv $SERVER_NAME.out ./nohup/$SERVER_NAME.out$DATE
nohup $JBOSS_HOME/bin/run.sh -b 0.0.0.0 -Dserver=$SERVER_NAME -Djboss.server.base.dir=$SERVER_HOME -Djboss.server.base.url=file://$SERVER_HOME -c $SERVER_NAME -g $PARTITION_NAME -u $MULTICAST_ADDR >> $SERVER_NAME.out &


if [ e$1 = "enotail" ]
then
    echo "Starting... $SERVER_NAME"
    exit;
fi

tail -f $SERVER_NAME.out
